#ifndef	_SCI_H
#define	_SCI_H
/***********************************************************************************************************************
**                                                    Includes                                                        **
***********************************************************************************************************************/

#include "Std_Types.h"
#include "Twi_Quene.h"

/***********************************************************************************************************************
**                                                  Global Symbols                                                    **
***********************************************************************************************************************/

#define AFE_ID				0x34
#define FAE_RSTAddr 	 	0xEA
#define CELL_NUM			15
#define CALC_TIMES			10
#define SCONF1_INIT_VAL     0x5F
#define SCONF2_INIT_VAL     0x01
#define CONF_INIT_VAL 	    0x08  //  0x00
#define BAVL_INIT_VAL		0x96
#define LOV_INIT_VAL		0x64
#define AFE_UV_INIT_VAL     0x5A
#define AFE_OCD1V_INIT_VAL  0x30
#define AFE_OCD2V_INIT_VAL  0x22
#define AFE_SCV_INIT_VAL    0x00    //lmy 0x01
#define AFE_OCCV_INIT_VAL   0x31
#define AFE_OTC_INIT_VAL    0xFF
#define AFE_UTC_INIT_VAL    0xFF
#define AFE_OTD_INIT_VAL    0xFF
#define AFE_UTD_INIT_VAL    0xFF
#define AFE_OTCR_INIT_VAL   0xFF
#define AFE_UTCR_INIT_VAL   0xFF

#define BALANCE_VAL			0xff0f
#define SWITCH_AFE2

/***********************************************************************************************************************
**                                                Global Data Types                                                   **
***********************************************************************************************************************/

typedef enum{
	Normal,
	Idle,
	Sleep,
}AFE_ModeType;

typedef enum{
	//mosfet
	CHG = 4,
	DSG,
	PCHG,
}AFE_MosCtrlType;

typedef enum{
	VOL,
	TEP,
	TR,
	CUR,
	VOL1,
	TEP1,
	TR1,
	CUR1,
	STATUS,
	STATUS1
}AFE_StepType;

typedef struct _INFORM							
{
	uint16		VCell[CELL_NUM];
	uint16		TCell[3];
	uint8		CTR;
	uint16		CCell;
    uint8       Alive;
    BOOL        Balance;
	BOOL		OCD1Sta;
	BOOL		OCD2Sta;
	BOOL		OCCSta;
	BOOL		SCSta;
    AFE_ModeType    Mode;
	AFE_StepType   	step;
}AFE_Info_Type;

/***********************************************************************************************************************
**                                                  Global Functions                                                  **
***********************************************************************************************************************/
/* init all afe chip */
Std_ReturnType AFE_Init(void);
/* reset afe1 and afe2 */
Std_ReturnType ResetAFE(void);
/* read vol cur temp status ... by cycle */
void AFE_MainFunc(void);
/* opend or close balance control */
Std_ReturnType AFE_BalanceCtrl(uint32 ctrlCmd);
/* open or close charge mos */
Std_ReturnType AFE_MosfetCtrl(AFE_MosCtrlType ctrl,BOOL val);
/* get data struct pointer */
AFE_Info_Type* Afe_GetAfeInfo(uint8 channel);
/* set work mode */
void AFE_SetMode(AFE_ModeType mode);
/* read mosfet status */
uint8 AFE_ReadInfo(AFE_MosCtrlType ctrl);
/* read balance status */
Std_ReturnType AFE_ReadBalance(uint32 *statusValue);
/* not use */
Std_ReturnType AFE_SetUV(uint8 val);

#endif
